#pragma once

#include <iostream>
#include <pthread.h>

class Task{
    private:
        int x;
        int y;
        char op; //+-*/%
    public:
        Task() //无参构造一定要有的
        {}
        Task(int _x, int _y, char _op):x(_x),y(_y),op(_op)
        {}
        void operator()()
        {
            run();
        }
        void run()
        {
            int z = -1;
            switch(op){
                case '+':
                    z = x + y;
                    break;
                case '-':
                    z = x - y;
                    break;
                case '*':
                    z = x * y;
                    break;
                case '/':
                    if(0 != y) z = x / y;
                    else std::cout << "Warning: div zero!" <<std::endl;
                    break;
                case '%':
                    if(0 != y) z = x % y;
                    else std::cout << "Warning: div zero!" <<std::endl;
                    break;
                default:
                    std::cout << "unknow operator!" << std::endl;
                    break;
            }
            std::cout <<"thread "<< "[" << pthread_self() << "] handler task done : "<< x << op << y << "=" << z << std::endl;
        }
        ~Task(){}
};
